package com.dinghui.pay.common;

import com.dinghui.pay.constant.HttpStatus;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;

/**
 * 
 * @author helloworld
 *
 * @param <T>
 */
@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseResult<T> {

    private static final long serialVersionUID = 1L;

    private int code;
    private String msg;
    private Object data;

    public ResponseResult() {
    }

    public ResponseResult(T result) {
        this.code = HttpStatus.SUCCESS;
        this.data = result;
    }

    public ResponseResult(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResponseResult success() {
        return ResponseResult.success("操作成功");
    }

    public static ResponseResult success(String msg) {
        return new ResponseResult(HttpStatus.SUCCESS, msg, new ArrayList<>());
    }

    public static ResponseResult success(Object data) {
        return new ResponseResult(HttpStatus.SUCCESS, "操作成功", data);
    }

    public static ResponseResult success(String msg, Object data) {
        return new ResponseResult(HttpStatus.SUCCESS, msg, data);
    }

    public static ResponseResult error() {
        return ResponseResult.error("操作失败");
    }

    public static ResponseResult error(String msg) {
        return new ResponseResult(HttpStatus.ERROR, msg, new ArrayList<>());
    }

    public static ResponseResult error(Object data) {
        return new ResponseResult(HttpStatus.ERROR, "操作失败", data);
    }

    public static ResponseResult error(int code, String msg) {
        return new ResponseResult(code, msg, new ArrayList<>());
    }

    public static ResponseResult error(String msg, Object data) {
        return new ResponseResult(HttpStatus.ERROR, msg, data);
    }

}
